<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="https://unpkg.com/vue@next"></script>
  <style>
    .header {
      color: red;
    }
  </style>
</head>
<body>
  <div id="app">
    <base-component></base-component>
  </div>

  <script>
    const app = Vue.createApp({
      setup() {
        const location = Vue.ref('North Pole')
        const geolocation = Vue.reactive({
          longitude: 90,
          latitude: 135
        })
        const updateLocation = () => {
          location.value = 'South Pole'
        }
        Vue.provide('location', location)
        Vue.provide('geolocation', geolocation)
        Vue.provide('updateLocation', updateLocation)

        return {
          location
        }
      }
    })

    app.component('base-component', {
      setup() {
        const userLocation = Vue.inject('location', 'The Universe')
        const userGeolocation = Vue.inject('geolocation')
        const updateUserLocation = Vue.inject('updateLocation')

        return {
          userLocation,
          userGeolocation,
          updateUserLocation
        }
      },
      template: `
      <div>{{ userLocation }}--{{ userGeolocation }}</div>
      <button @click="updateUserLocation">改变值</button>
      `
    })

    app.mount('#app')
  </script>
</body>
</html>